package com.wanwu.channel.biz;

import com.wanwu.channel.biz.mapper.PayOrderMapper;
import com.wanwu.channel.biz.mapper.ProfitSharingOrderMapper;
import com.wanwu.channel.biz.po.PayOrder;
import com.wanwu.channel.model.AccountPayReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.guangdian.ota.controller.WXPayReq;

import java.util.Date;

@Service
@Slf4j
public class PayOrderService {
    @Autowired
    private ProfitSharingOrderMapper tradeOrderMapper;
    @Autowired
    private PayOrderMapper payOrderMapper;

    public PayOrder insertWxPayOrder(WXPayReq wxPayReq){
        PayOrder payOrder = new PayOrder().setPayType(1)
                .setDescription(wxPayReq.getDescription()).setMchid(wxPayReq.getMchid())
                .setOutTradeNo(wxPayReq.getOutTradeNo())
                .setTotal(wxPayReq.getTotalAmount())
                .setUserid(wxPayReq.getUserid())
                .setExpireTime(wxPayReq.getTimeExpire())
                .setDeviceinfo(wxPayReq.getDeviceInfo())
                .setNotifyUrl(wxPayReq.getNotifyUrl())
                .setThirdTradeNo("")
                .setResult(wxPayReq.getResult())
                .setResultCode(wxPayReq.getResultCode())
                .setCreateTime(new Date())
                .setUpdateTime(new Date());
        int insert = payOrderMapper.insert(payOrder);
        return payOrder;
    }


    public void accountPay(AccountPayReq req){

        PayOrder payOrder = new PayOrder();
        payOrder.setPayType(req.getPayType());
        payOrder.setExpireTime(new Date());
        payOrder.setMchid(req.getSellerId());
        payOrder.setOutTradeNo(req.getOutTradeNo());
        payOrder.setThirdTradeNo(req.getOutTradeNo());
        payOrder.setUserid(req.getBuyerId());
        payOrder.setTotal(req.getTotal());

        payOrderMapper.insert(payOrder);
    }

}

